//
//  BoLangViewController.m
//  iOSHeartAnimation
//
//  Created by ddy on 2018/8/9.
//  Copyright © 2018年 ddy. All rights reserved.
//

#import "BoLangViewController.h"
#import "CycleWaveView.h"
#import "UIImageView+CycleExtension.h"
@interface BoLangViewController ()
/** wave */
@property (nonatomic, strong) CycleWaveView  *waveView;
@end

@implementation BoLangViewController
/** CycleWaveView */
- (CycleWaveView *)waveView{
    if(!_waveView){
        _waveView = [[CycleWaveView alloc]initWithFrame:CGRectMake(0, 150, [UIScreen mainScreen].bounds.size.width, 100)];
    }
    return  _waveView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    //画圆形
    [self c_drawCorner];
    //波浪
    [self c_initWave];
    //六边形
    [self c_initLiuBianXing];
}
//1.画圆形
- (void)c_drawCorner {
    ///第一种
    UIImageView *imgView1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 100, 100, 100)];
    imgView1.image = [UIImage imageNamed:@"aa.jpg"];
    //圆形图片
    [imgView1 cycle_circleImageView];
    //设置shadow
    imgView1.layer.shadowColor = [UIColor grayColor].CGColor;
    imgView1.layer.shadowOpacity = 1.0;
    imgView1.layer.shadowRadius = 2.0;
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:imgView1.frame];
    imgView1.layer.shadowPath = path.CGPath;
    [self.view addSubview:imgView1];
    
    ///第二种
    UIImageView *imgView2 = [[UIImageView alloc]initWithFrame:CGRectMake(150, 100, 100, 100)];
    imgView2.image = [UIImage imageNamed:@"aa.jpg"];
    //bezier曲线
    [imgView2 cycle_circleImageViewWithBezier];
    
    [self.view addSubview:imgView2];
    

    
}

//2.波浪
- (void)c_initWave{
    [self.view addSubview:self.waveView];
    self.waveView.c_speed = 3.0;
    self.waveView.c_waveHeight = 5.0;
    self.waveView.c_waveTotallHeight = 200;
    [self.waveView c_setfirstWaveColor:[UIColor redColor] firstWaveAlpha:0.3 secondWaveColor:[UIColor orangeColor] secondWaveAlpha:0.3];
    [self.waveView c_startWaving];
}





//3.六边形的layer
- (void)c_initLiuBianXing{
    UIImageView *imgView3 = [[UIImageView alloc]initWithFrame:CGRectMake(100, 400, 100, 100)];
//    imgView3.image = [UIImage imageNamed:@"aa.jpg"];
    
    [self layerWithWidth:imgView3 image:[UIImage imageNamed:@"aa.jpg"]];
    [self.view addSubview:imgView3];
}
- (void)layerWithWidth:(UIImageView *)imageView image:(UIImage *)image
{
  
    float left = 5.f;
    CGRect hexagnoRect =  CGRectMake(left, left, imageView.bounds.size.width-2*left, imageView.bounds.size.height-2*left);;
    //绘制一个六边形的layer，并复制一个image给他的contents
    CALayer *hexagonLayer = [CALayer layer];
    hexagonLayer.frame = hexagnoRect;

    CAShapeLayer * shapLayer = [CAShapeLayer layer];
    shapLayer.lineWidth = 1;
    shapLayer.strokeColor = [UIColor whiteColor].CGColor;
    shapLayer.path = [self getCGPath:hexagnoRect.size.width];
    hexagonLayer.mask = shapLayer;
    hexagonLayer.contents = (__bridge id _Nullable)(image.CGImage);


    CAShapeLayer *completeLayer = [CAShapeLayer layer];
    completeLayer.frame = CGRectMake(0, 0, imageView.bounds.size.width, imageView.bounds.size.height);
    [completeLayer addSublayer:hexagonLayer];
    completeLayer.path = [self getCGPath:imageView.bounds.size.width];
    completeLayer.fillColor = [UIColor lightGrayColor].CGColor;

    [imageView.layer addSublayer:completeLayer];

  
    
}
-(CGPathRef)getCGPath:(CGFloat)viewWidth{
    UIBezierPath * path = [UIBezierPath bezierPath];
    path.lineWidth = 1.0;
    [[UIColor whiteColor] setStroke];
    
    [path moveToPoint:CGPointMake((sin(M_1_PI / 180 * 60)) * (viewWidth / 2), (viewWidth / 4))] ;
    
    [path addLineToPoint:CGPointMake((viewWidth / 2), 0)];
    
    [path addLineToPoint:CGPointMake(viewWidth - ((sin(M_1_PI / 180 * 60)) * (viewWidth / 2)), (viewWidth / 4))];
    
    [path addLineToPoint:CGPointMake(viewWidth - ((sin(M_1_PI / 180 * 60)) * (viewWidth / 2)), (viewWidth / 2) + (viewWidth / 4))];
    
    [path addLineToPoint:CGPointMake((viewWidth / 2), viewWidth)];
    
    [path addLineToPoint:CGPointMake((sin(M_1_PI / 180 * 60)) * (viewWidth / 2), (viewWidth / 2) + (viewWidth / 4))];
    
    [path closePath];
    return path.CGPath;
}







@end
